package com.itsm.controller;

import com.itsm.entity.Process;
import com.itsm.entity.User;
import com.itsm.service.ProcessApproveService;
import com.itsm.service.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class ProcessApproveController {

    @Autowired
    private ProcessApproveService processApproveService;
    @Autowired
    private UserMapper userMapper;

    @GetMapping("getAllApp")
    public List<Process> getAllApp(HttpServletRequest request){
        return processApproveService.getAllApp((String) request.getSession().getAttribute("name"));
    }

    //弃用
    @GetMapping("getAllApprove")
    public List<Process> getAllApprove(HttpServletRequest request){
        return processApproveService.getAllApprove((String) request.getSession().getAttribute("userid"));
    }
    @GetMapping("getAllUnApp")
    public List<Process> getAllUnApp(HttpServletRequest request){
        String name = (String) request.getSession().getAttribute("name");
        if(userMapper.getUserByName(name).getPost()==2){
            return processApproveService.getAllUnApp1(name,userMapper.getUserByName(name).getPlant());
        }

        return processApproveService.getAllUnApp(name);
    }
}
